﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace XRERP.Filters
{
    public class Authentic : FilterAttribute,IAuthorizationFilter
    {
        
        public void OnAuthorization(AuthorizationContext filterContext)
        {
            //过滤匿名访问页面
            bool filterpage = filterContext.ActionDescriptor.IsDefined(typeof(AllowAnonymousAttribute), true)||
                filterContext.ActionDescriptor.ControllerDescriptor.IsDefined(typeof(AllowAnonymousAttribute), true);

            if(filterpage)
            {
                return;
            }

            var Url = new UrlHelper(filterContext.RequestContext);
            var url = Url.Action("Index", "Login");
            filterContext.Result = new RedirectResult(url);
            
        }
    }
}